from abc import ABC, abstractmethod


# 策略接口
class Strategy(ABC):
    @abstractmethod
    def execute(self, data):
        pass

    # 具体策略A


class ConcreteStrategyA(Strategy):
    def execute(self, data):
        return f"Strategy A: {data}"

    # 具体策略B


class ConcreteStrategyB(Strategy):
    def execute(self, data):
        return f"Strategy B: {data.upper()}"

    # 上下文（客户端）


class Context:
    def __init__(self, strategy):
        self.strategy = strategy

    def process_data(self, data):
        # 客户端代码调用策略对象的算法
        return self.strategy.execute(data)

    # 使用示例


if __name__ == "__main__":
    # 创建一个上下文对象，并注入具体策略A
    context_a = Context(ConcreteStrategyA())
    result_a = context_a.process_data("Hello, world!")
    print(result_a)  # 输出: Strategy A: Hello, world!

    # 创建一个上下文对象，并注入具体策略B
    context_b = Context(ConcreteStrategyB())
    result_b = context_b.process_data("Hello, world!")
    print(result_b)  # 输出: Strategy B: HELLO, WORLD!